package com.demo2do.fms.admin.entity.search.data;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;


/**
 * 查询装卸地代码所用条件
 * 
 * @author Chang Liu
 *
 */
public class LoadPlaceSearch implements QueryBuilder {
	
	/** 装卸地名称 */
	private String facilityName;
	
	/** 装卸地所在城市 */
	private String cityName;
	
	private QueryOrder order;
	    
	private QueryFilter filter;

	/**
	 * The default constructor
	 */
	public LoadPlaceSearch() {
		order = new QueryOrder();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
    public QueryFilter getPreparedFilter(boolean refresh) {
		
		if(filter == null || refresh) {

			filter = new QueryFilter().addLike("name", facilityName)
			                          .addLike("city.name", cityName);
			
        }
		
		return filter;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		String sentence = "FROM LoadPlace WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		return sentence;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/**
	 * 
	 * @return
	 */
	public QueryFilter getFilter(){
		return getPreparedFilter(false);
	}
	

	/**
	 * @return the facilityName
	 */
	public String getFacilityName() {
		return facilityName;
	}

	/**
	 * @return the cityName
	 */
	public String getCityName() {
		return cityName;
	}

	/**
	 * @param facilityName the facilityName to set
	 */
	public void setFacilityName(String facilityName) {
		this.facilityName = facilityName;
	}

	/**
	 * @param cityName the cityName to set
	 */
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

}
